const Service = require('egg').Service

class AdminService extends Service {

  async getAdminList() {
    let res = await this.app.model.Admin.findAll({
      attributes: ['id','adminname','headImg']
    })
    // console.log(res);
    return res
  }

  async postAdmin(body) {
    try{
      return await this.app.model.Admin.create({
        adminname:body.adminname,
        password:body.newpassword,
        headImg: "https://xingqiu-tuchuang-1256524210.cos.ap-shanghai.myqcloud.com/1338/baseimg.jpeg",
        auth:1
      })
    }catch(error){

    }
  }

  async putAdmin(id,newpassword) {
    try{
      return await this.app.model.Admin.update({
        password:newpassword
      },{
        where:{
          id
        }
      })
    }catch(error){

    }
  }

  async delAdmin(id) {
    try{
      return await this.app.model.Admin.destroy({
        where:{
          id
        }
      })
    }catch(error){

    }
  }

}

module.exports = AdminService